home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_03 / 1n03010b < prev    next >
Text File  |  1990-06-12  |  750b  |  43 lines

  1.  
  2. Listing 5
  3.  
  4. procedure not_NIL(p : pointer);
  5. function hexstr(w : word) : string;
  6. function ptrstr(p : pointer) : string;
  7.  
  8. {*
  9.  * A safer dispose
  10.  *}
  11. procedure dispose(var p : pointer);
  12.         begin
  13.         system.dispose(p);
  14.         p := NIL;
  15.         end;
  16.  
  17. var
  18.         p1, p2, p3, p4 : ^longint;
  19. begin
  20. new(p1);
  21. {$ifdef DEBUG} not_NIL(p1); {$endif}
  22. p1^ := 1;
  23. new(p2);
  24. {$ifdef DEBUG} not_NIL(p2); {$endif}
  25. p2^ := 2;
  26. new(p3);
  27. {$ifdef DEBUG} not_NIL(p3); {$endif}
  28. p3^ := 3;
  29. dispose(pointer(p2));
  30. new(p4);
  31. {$ifdef DEBUG} not_NIL(p4); {$endif}
  32. p4^ := 4;
  33. {$ifdef DEBUG} not_NIL(p2); {$endif}
  34. p2^ := -2;
  35. writeln('p1^ = ', p1^);
  36. writeln('p2^ = ', p2^);
  37. writeln('p3^ = ', p3^);
  38. writeln('p4^ = ', p4^);
  39. end.
  40.  
  41. ----------
  42.  
  43.